// 全局
import {getTopList} from "@/network/discover/recommend";
import {getPlaylistTrackAll} from "@/network/songs/musicrelated";
import {getCookie} from "@/until/cookie";

interface stateInterface {
    list: any;
    artistToplist: any;
    rewardToplist: any;
    soaringList: any;
    newSongList: any;
    OriginalList: any;
}

export default {
    namespaced: true,
    state: {
        list: undefined,
        artistToplist: undefined,
        rewardToplist: undefined,
        soaringList: undefined,
        newSongList: undefined,
        OriginalList: undefined,
    },
    mutations: {
        GET_LIST(state: stateInterface, value: any) {
            state.list = value;
        },
        GET_ARTIST_TOP_LIST(state: stateInterface, value: any) {
            state.artistToplist = value;
        },
        GET_REWARD_TOP_LIST(state: stateInterface, value: any) {
            state.rewardToplist = value;
        },
        GET_SOARING_LIST(state: stateInterface, value: any) {
            state.soaringList = value;
        },
        GET_NEW_SONG_LIST(state: stateInterface, value: any) {
            state.newSongList = value;
        },
        GET_ORIGINAL_LIST(state: stateInterface, value: any) {
            state.OriginalList = value;
        },
    },
    actions: {
        //获取recommend页面topList的展示信息
        async getTopList(context: any, value: string) {
            const {data: res} = await getTopList(value);
            context.commit("GET_LIST", res.list);
            context.commit("GET_ARTIST_TOP_LIST", res.artistToplist);
            context.commit("GET_REWARD_TOP_LIST", res.rewardToplist);
            const {data: soaringList} = await getPlaylistTrackAll(res.list[0].id, getCookie(), 0, 10);
            const {data: newSongList} = await getPlaylistTrackAll(res.list[1].id, getCookie(), 0, 10);
            const {data: OriginalList} = await getPlaylistTrackAll(res.list[2].id, getCookie(), 0, 10);
            context.commit("GET_NEW_SONG_LIST", newSongList.songs);
            context.commit("GET_SOARING_LIST", soaringList.songs);
            context.commit("GET_ORIGINAL_LIST", OriginalList.songs);
        },
    },
    getters: {},
};
